# Maintainer : Christian Rebischke <Chris.Rebischke@archlinux.org>
# Maintainer : Bruno Pagani <archange@archlinux.org>
# Contributor: Frederik "Freso" S. Olesen <archlinux@freso.dk>
# Contributor: Bastien Traverse <firstname at lastname dot email>
# Contributor: Samantha Baldwin <fuhsaz+git@cryptic.li>
# Contributor: Caleb Reach <jtxx000@gmail.com>
# Contributor: Felix Yan <felixonmars@gmail.com>
# Contributor: Karol "Kenji Takahashi" Woźniak <kenji.sx>
# Contributor: Mantas Mikulėnas <grawity@gmail.com>

pkgname=whipper
pkgver=0.10.0
pkgrel=5
pkgdesc="Python CD-DA ripper preferring accuracy over speed"
arch=(loong64 x86_64)
url="https://github.com/whipper-team/whipper"
license=(GPL3)
depends=(
  cdrdao
  flac
  libcdio-paranoia
  libsndfile
  python-discid
  python-gobject
  python-musicbrainzngs
  python-mutagen
  python-pycdio
  python-ruamel-yaml
  python-setuptools
  sox
)
checkdepends=(
  python-twisted
)
makedepends=(python-setuptools-scm python-docutils)
optdepends=('python-pillow: cover art support')
conflicts=(accuraterip-checksum)
provides=(accuraterip-checksum)
source=(${url}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
        whipper-ruamel.yaml-0.17.patch::https://github.com/whipper-team/whipper/pull/543.patch
	test-fixup.patch)
sha512sums=('728ad98185aa2d29f4fb215a597136691bb2c3590b3cac4f659238f90a3b4328c377fafe830a725b655f050538739f404b3eca853db4c39001d1b9d721dc7fd8'
            '893e2f23717633971410e0f9917345eaec5af313d83702b36a2693b51eaf54d755d58db864de82e13e8506dc98ab548334d7ba6d02fd6c200bd0670e4bca73bf'
            '17e817faf7a9244fe9b0c11f1cba71ec4a4eb7ee880fc16a2a3e2033cf1db9f16ab3cad18e20c2e02d5e656c2ccbc1143f744ffd0e950fe6bfd3512d58731f71')

prepare() {
  cd ${pkgname}-${pkgver}
  patch -p1 -i ../whipper-ruamel.yaml-0.17.patch
  patch -p1 -i ../test-fixup.patch # tests depend on an external service... which can change test data
}

build() {
  cd ${pkgname}-${pkgver}
  echo "Version: ${pkgver}" > PKG-INFO
  python setup.py build
  cd man
  make
}

check() {
  cd ${pkgname}-${pkgver}
  local python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  PYTHONPATH="build/lib.linux-${CARCH}-cpython-${python_version}/" python -m unittest discover
}

package() {
  cd ${pkgname}-${pkgver}
  python setup.py install --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 -t "${pkgdir}"/usr/share/man/man1/ man/*.1
}
